package com.wngbms.netty.book._06endec._01;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.embedded.EmbeddedChannel;

public class Integer2StringDecoderTest {

    public static void main(String[] args) {
        ChannelInitializer<EmbeddedChannel> channelInitializer = new ChannelInitializer<EmbeddedChannel>() {

            @Override
            protected void initChannel(EmbeddedChannel ch) throws Exception {
                ChannelPipeline pipeline = ch.pipeline();
                // 顺序不能反
                pipeline.addLast(new Byte2IntegerDecoder());
                pipeline.addLast(new Integer2StringDecoder());
                pipeline.addLast(new StringProcessHandler());
            }
        };

        byte[] buf = new byte[]{(byte) 1, (byte) 8, (byte) 1, (byte) 1, (byte) 1, (byte) 2, (byte) 3};
        EmbeddedChannel embeddedChannel = new EmbeddedChannel(channelInitializer);
        for (int i = 0; i < 5; i++) {
            ByteBuf buffer = Unpooled.buffer();
            buffer.writeBytes(buf);
            embeddedChannel.writeInbound(buffer);
        }
    }

}
